//
//  JKRFeedAuthorLayout.m
//  JKRFeedDemo
//
//  Created by Lucky on 2017/12/10.
//  Copyright © 2017年 Lucky. All rights reserved.
//

#import "JKRFeedAuthorLayout.h"

@implementation JKRFeedAuthorLayout

- (instancetype)initWithModel:(JKRFeedDataModel *)model {
    self = [super init];
    
    if (model.order.order_type == 1) { // 陪玩
        switch (model.order.order_status) {
            case 1: // 已发布
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else { // 游客
                    
                }
            }
                break;
            case 4: // 超时无人购买
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else { // 游客
                    
                }
            }
                break;
            case 6: // 老板买单
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 7: // 超时未填写结果
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 8: // 填写结果-打了
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 9: // 填写结果-没打
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 10: // 填写打了超时未确认或者确认服务
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 11: // 发起投诉
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 12: // 申诉成功
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            case 13: // 申诉失败
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if([model.order.payer.uid isEqualToString:CurrentUserID]) { // 老板
                    
                } else { // 游客
                    
                }
            }
                break;
            default:
                break;
        }
    } else if (model.order.order_type == 2) { // 约玩
        switch (model.order.order_status) {
            case 1: // 已发布
            {
                BOOL isSignUp = NO;
                for (JKRFeedOrderCandidate *candidate in model.order.candidates) {
                    if ([candidate.uid isEqualToString:CurrentUserID]) {
                        isSignUp = YES;
                        break;
                    }
                }
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if(isSignUp) { // 报名者
                    
                } else { // 游客
                    
                }
            }
                break;
            case 2: // 超时无人报名
            {
                BOOL isSignUp = NO;
                for (JKRFeedOrderCandidate *candidate in model.order.candidates) {
                    if ([candidate.uid isEqualToString:CurrentUserID]) {
                        isSignUp = YES;
                        break;
                    }
                }
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if(isSignUp) { // 报名者
                    
                } else { // 游客
                    
                }
            }
                break;
            case 3: // 超时未选大神
            {
                BOOL isSignUp = NO;
                for (JKRFeedOrderCandidate *candidate in model.order.candidates) {
                    if ([candidate.uid isEqualToString:CurrentUserID]) {
                        isSignUp = YES;
                        break;
                    }
                }
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if(isSignUp) { // 报名者
                    
                } else { // 游客
                    
                }
            }
                break;
            case 5: // 选择大神
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 7: // 超时未填写结果
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 8: // 填写结果-打了
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 9: // 填写结果-没打
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 10: // 填写打了超时未确认或者确认服务
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 11: // 发起投诉
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 12: // 申诉成功
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            case 13: // 申诉失败
            {
                if ([model.feed.author.uid isEqualToString:CurrentUserID]) { // 发布者
                    
                } else if ([model.order.candidate.uid isEqualToString:CurrentUserID]) { // 大神
                    
                } else { // 游客
                    
                }
            }
                break;
            default:
                break;
        }
        
    }
    
    self.headerImageFrame = CGRectMake(15, 15, 43, 43);
    self.headerImageURL = [NSURL URLWithString:model.feed.author.thumbnail];
    NSMutableAttributedString *priceString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"一口价%zd元", model.order.price] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:UIColorHex(CE0008)}];
    {
        YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        container.maximumNumberOfRows = 1;
        self.priceLabelLayout = [YYTextLayout layoutWithContainer:container text:priceString];
        self.priceLabelFrame = CGRectMake(kScreenWidth - self.priceLabelLayout.textBoundingRect.size.width - 15, 15, self.priceLabelLayout.textBoundingRect.size.width, self.priceLabelLayout.textBoundingRect.size.height);
    }
    
    NSMutableAttributedString *nameString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ", model.feed.author.name] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:UIColorHex(444444)}];
    {
        CGFloat imageWidth;
        if (model.feed.author.baoji_level == 100 || model.feed.author.baoji_level == 101 || model.feed.author.baoji_level == 102) {
            imageWidth = 31;
        } else {
            imageWidth = 0;
        }
        self.baojiImageName = [NSString stringWithFormat:@"bj_%zd", model.feed.author.baoji_level];
        YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(kScreenWidth - self.priceLabelFrame.size.width - 15 - 67 - imageWidth - 10, MAXFLOAT)];
        container.maximumNumberOfRows = 1;
        nameString.lineBreakMode = NSLineBreakByTruncatingMiddle;
        
        YYTextHighlight *highLight = [YYTextHighlight new];
        highLight.userInfo = @{kFeedTopClickUser:model.feed.author.uid};
        [nameString setTextHighlight:highLight range:nameString.string.rangeOfAll];
        
        self.nameLabelLayout = [YYTextLayout layoutWithContainer:container text:nameString];
        self.nameLabelFrame = CGRectMake(67, 16, self.nameLabelLayout.textBoundingRect.size.width, self.nameLabelLayout.textBoundingRect.size.height);
        
        self.baoJiImageViewFrame = CGRectMake(CGRectGetMaxX(self.nameLabelFrame), 16, imageWidth, 15);
    }
    
    {
        NSMutableAttributedString *timeString = [[NSMutableAttributedString alloc] initWithString:model.feed.date];
        timeString.font = [UIFont systemFontOfSize:12];
        timeString.color = UIColorHex(7E7E7E);
        YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        container.maximumNumberOfRows = 1;
        self.timeLabelLayout = [YYTextLayout layoutWithContainer:container text:timeString];
        self.timeLabelFrame = CGRectMake(68, CGRectGetMaxY(self.headerImageFrame) - self.timeLabelLayout.textBoundingRect.size.height, self.timeLabelLayout.textBoundingRect.size.width, self.timeLabelLayout.textBoundingRect.size.height);
    }
    
    {
        NSMutableAttributedString *gameString = [[NSMutableAttributedString alloc] initWithString:model.order.game_name];
        gameString.font = [UIFont systemFontOfSize:12];
        gameString.color = UIColorHex(7E7E7E);
        YYTextContainer *container = [YYTextContainer containerWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
        container.maximumNumberOfRows = 1;
        self.gameLabelLayout = [YYTextLayout layoutWithContainer:container text:gameString];
        self.gameLabelFrame = CGRectMake(kScreenWidth - self.gameLabelLayout.textBoundingRect.size.width - 15, CGRectGetMaxY(self.headerImageFrame) - self.gameLabelLayout.textBoundingRect.size.height, self.gameLabelLayout.textBoundingRect.size.width, self.gameLabelLayout.textBoundingRect.size.height);
    }
    
    return self;
}

@end
